home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0083_Re: DELPHI EQUIVALENT OF VB SHELL COMMAN.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  1.8 KB  |  63 lines

  1. {
  2. >>
  3. >> DELPHI EQUIVALENT TO VB SHELL COMMAND
  4. >>
  5. [Trimmed]
  6. >
  7. >> 3: Will I have a method of monitoring the DOS program/shell to I
  8. >>    know when it has terminated?
  9. >>
  10. >
  11.  
  12. You have to dig about a bit in the API to do this, but the answer is
  13. basically to keep enumerating the task list until the task that you
  14. started is no longer present. Do something like this to get the
  15. Hinstance of your new task (The API call used to enumerate the task list
  16. needs a Hinstance):
  17. }
  18.     {Execute batch file}
  19.     StrPCopy(Templine, 'temp.bat');
  20.     TaskHandle := ShellExecute(frmMain.Handle, NIL, 'command.com',
  21.                   templine,
  22.                   Tempdir,
  23.                   SW_MINIMIZE);
  24.  
  25. and monitor it with a function like this:
  26.  
  27. <------------------------------------------------->
  28.  
  29.     function CheckTask(hInstance: WORD): Boolean;
  30.     var
  31.         TaskInfo: TTASKENTRY;
  32.         RetVal: Boolean;
  33.     begin
  34.         TaskInfo.dwSize := SizeOf(TTASKENTRY);
  35.         RetVal := FALSE;
  36.         if(TaskFirst(@TaskInfo)) then
  37.         begin
  38.             repeat
  39.                 if(TaskInfo.hInst = hInstance) then
  40.                 begin
  41.                     RetVal := TRUE;
  42.                     Break;
  43.                 end;
  44.             until (TaskNext(@TaskInfo) = FALSE);
  45.         end;
  46.         CheckTask := RetVal;
  47.     end;
  48. <-------------------------------------------------->
  49.  
  50. This runs down the task list, trying to find the task with the specified
  51. Hinstance, returning true if it is still there. To use this function,
  52. simply call it in a loop like this
  53.  
  54.     while CheckTask(TaskHandle) do
  55.     begin
  56.         Application.ProcessMessages;
  57.     end;
  58.  
  59. Hope this helps.
  60.  
  61. ---------------------------------------------------------------------
  62. Marc Evans                      marc@leviathn.demon.co.uk
  63.